<?php
include_once('inc/functions.inc.php');
$db = DbManager::getMe();
if (!isEmpty(getParam('operation'))) {

    switch (getParam('operation')) {
        case 'e': {
                fntAcademicoCobrosContabilizacionEmpresas($db);
                break;
            }
        case 'f': {
                fntAcademicoCobrosContabilizacionFacturas($db);
                break;
            }
        case 'p': {
                fntAcademicoCobrosContabilizacionPartida($db);
                break;
            }
        case 's': {
                fntAcademicoCobrosContabilizacionGrabar($db);
                break;
            }
        case 'cargos': {
                fntBuscarCargos($db);
                break;
            }
        case 'showdetalleanulacion': {
                fntShowDetalleAnulacion($db);
                break;
            }
        case 'anulacobro': {
                fntAnulaCobro($db);
                break;
            }
    }
    die();
}

/**
 * Muestra el detalle de la anulacion
 * @param type $db 
 */
function fntShowDetalleAnulacion($db) {
    $idGrado = getParam("idGrado");
    $mes = getParam("idMes");
    $cargo = getParam("idCargo");

    $q = " select  * from 	cllg_academico_cobros c
	where DATE_FORMAT(c.FECHA,'%m') = $mes and
              c.ESTADO = 'INGRESADO' and
              c.FK_CARGO_DETAIL_ID = $cargo";

    if ($idGrado == "999") {
        $q = " select  * from 	cllg_academico_cobros c
	where DATE_FORMAT(c.FECHA,'%m') = $mes and
              c.ESTADO = 'INGRESADO' and NOT ISNULL(c.FK_CARGO_MANUAL)";
    }

    $rs = $db->queryToArray($q, true);
    $url = "idMes=$mes&idCargo=$cargo&idGrado=$idGrado";
    ?>
    <div id="contenidocobrosanulacion">
        <script type="text/javascript">
            (function($){
                $("#checkAll").click( function() {
                    $("[name*='chckcobro_']").attr("checked",$(this).attr("checked"));	                    
                });		  
            })(jQuery)     
        </script>
        <div class="dttb"  >
            <table>
                <caption>
                    <button type="button" onclick="javascript:fntAnulaCobro('<?php echo $url ?>');">
                        <img title="Anular" src="../img/accepted.png" width="16" height="16" />
                        Anular</button>                    
                    <button type="button" onclick="$('#cobrosanulacion').dialog('close');">
                        <img title="Cerrar" src="../img/denied.png" width="16" height="16" />
                        Cerrar</button>                    
                </caption>
                <thead>
                    <tr>
                        <th><input type="checkbox" id="checkAll" /></th>
                        <th>Codigo Est./Benef.</th>
                        <th>Id</th>
                        <th>Fecha</th>
                        <th>Estado</th>
                        <th>Tipo</th>                        
                        <th>Valor</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($rs as $r) {
                        ?>
                        <tr>
                            <td><input type="checkbox" name="chckcobro_<?php echo $r["ID"]; ?>" /> </td>
                            <td><?php echo $r["FK_ESTUDIANTE"]; ?></td>
                            <td><?php echo $r["ID"]; ?></td>
                            <td><?php echo $r["FECHA"]; ?></td>
                            <td><?php echo $r["ESTADO"]; ?></td>
                            <td><?php echo $r["TIPO"]; ?></td>                            
                            <td><?php echo $r["VALOR"]; ?></td>
                        </tr>    
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
    &nbsp;
    <?php
}

/**
 * Anula un cobro
 * @param type $db 
 */
function fntAnulaCobro($db) {
    while ($arrPost = each($_POST)) {
        $arrExplode = explode("_", $arrPost["key"]);
        if ($arrExplode[0] == "chckcobro") {
            revertirCobroNoContable($arrExplode[1], $db);
        }
    }
    $idGrado = getParam("idGrado");
    $mes = getParam("idMes");
    $cargo = getParam("idCargo");
    echo "idMes=$mes&idCargo=$cargo&idGrado=$idGrado";
}

function fntBuscarCargos($db, $defGrado = null, $defCargo = null) {
    $query = "select a.FK_GRADO,b.ID, b.DESCRIPCION, b.TIPO  
		  FROM cllg_academico_cargos a, cllg_academico_cargos_detail b
			  where a.CODIGO=b.FK_CARGOS AND a.FK_GRADO=" . (($defGrado == null) ? getParam("sltAcademicoCobrosContabilizacionGrado") : $defGrado);
    $res = $db->queryToArray($query);
    ?>

    <select name="sltAcademicoCobrosContabilizacionCargo" id="sltAcademicoCobrosContabilizacionCargo">    
        <option value="" >Ver Todos</option>
        <?php foreach ($res as $row) { ?>		
            <option value="<?php echo $row['ID'] . (($defCargo != null && $defCargo == $row['ID']) ? 'selected="selected"' : ''); ?> " ><?php echo $row['DESCRIPCION']; ?></option>

        <?php } ?>  
    </select>
    <script type="text/javascript">
        $("#sltAcademicoCobrosContabilizacionCargo").change( function(){
            fntAcademicoCobrosContabilizacionFacturas();
        });
    </script>
    <?php
}

function fntAcademicoCobrosContabilizacionEmpresas($db) {
    fntEmpresasDraw($db, "sltAcademicoCobrosContabilizacionEmpresas");
    ?>
    <script type="text/javascript">
        $("select[name='sltAcademicoCobrosContabilizacionEmpresas']").change( function() {
            fntAcademicoCobrosContabilizacionFacturas();
            var objInterface = $("#divAcademicoCobrosContabilizacionPartida");
            objInterface.html("");
        });
    </script>
    <?php
}

function fntAcademicoCobrosContabilizacionFacturas($db) {
    /* $strQuery = "select a.FK_GRADO,d.NOMBRE,
      DATE_FORMAT(c.FECHA,'%m') MES_CARGO,
      b.DESCRIPCION,b.ID,
      sum(c.VALOR) AS TOTAL
      from cllg_academico_cargos a,
      cllg_academico_cargos_detail b,
      cllg_academico_cobros c,
      cllg_academico_grados d
      where a.ID=b.FK_CARGOS and
      c.FK_CARGO_DETAIL_ID=b.ID and
      c.ESTADO = 'INGRESADO' and
      a.FK_GRADO=d.ID and c.PARTIDA_CARGOS is null";
      $strQuery.= " GROUP BY a.FK_GRADO,d.NOMBRE,b.DESCRIPCION,b.ID,MES_CARGO"; */
    $strQuery = " select a.FK_GRADO,d.NOMBRE,
		            DATE_FORMAT(c.FECHA,'%m') MES_CARGO,
        		    b.DESCRIPCION,b.ID,
					sum(c.VALOR) AS TOTAL 						            
						from cllg_academico_cargos a, 
                			cllg_academico_cargos_detail b, 
        	    			cllg_academico_cobros c,
                			cllg_academico_grados d
			      where a.ID=b.FK_CARGOS and 
              c.FK_CARGO_DETAIL_ID=b.ID and 
			  c.ESTADO = 'INGRESADO' and	
              a.FK_GRADO=d.ID and c.PARTIDA_CARGOS is null GROUP BY a.FK_GRADO,d.NOMBRE,b.DESCRIPCION,b.ID,MES_CARGO
            union              
            select 999,'N/A',DATE_FORMAT(c.FECHA,'%m') MES_CARGO, a.DESCRIPCION ,a.ID,sum(c.VALOR)
            from cllg_academico_cobros c, cllg_academico_cargo_manual a, cllg_academico_cargo_cuenta cc 
                    where c.ESTADO = 'INGRESADO' AND c.FK_CARGO_MANUAL=cc.ID and cc.FK_CARGO_MANUAL=a.ID               
                GROUP BY a.DESCRIPCION,a.ID,MES_CARGO  ";
    $qTMP = $db->query($strQuery);
    $intNumRows = $db->num_rows;
    ?>

    <div style="width: 100%; float: left;">
        <div style="width: 800px; float: left; height: 35px;">
            <div style="width: 100px; float: left; text-align: center; border-bottom: 1px solid black;"><b>Grado</b></div>
            <div style="width: 60px; float: left; text-align: center; border-bottom: 1px solid black;"><b>Mes</b></div>
            <div style="width: 200px; float: left; text-align: center; border-bottom: 1px solid black;"><b>Cargo</b></div>
            <div style="width: 200px; float: left; text-align: center; border-bottom: 1px solid black;"><b>Total</b></div>
            <div style="width: 150px; float: left; text-align: center; border-bottom: 1px solid black;">&nbsp;</div>
        </div>
        <?php
        if ($intNumRows > 0) {
            ?>
            <div style="width: 800px; height: 350px; overflow: auto; float: left;" id="detallecargos">
                <?php
                $vMes = $vAntMes = null;
                $vGrado = $vAntGrado = null;
                while ($rTMP = $db->fetch_array($qTMP)) {
                    $vAntMes = $vMes;
                    $vMes = $rTMP["MES_CARGO"];
                    $vAntGrado = $vGrado;
                    $vGrado = $rTMP["NOMBRE"];
                    $url = "idGrado=" . $rTMP["FK_GRADO"] . "&idCargo=" . $rTMP["ID"] . "&idMes=" . $rTMP["MES_CARGO"];
                    ?>
                    <div style="height: 30px;" class="row" >
                        <div style="width: 100px; float: left; text-align: center;"><?php print $rTMP["NOMBRE"]; ?> </div>
                        <div style="width: 60px; float: left; text-align: center;"><?php print $rTMP["MES_CARGO"]; ?></div>
                        <div style="width: 250px; float: left; text-align: center;"><?php print $rTMP["DESCRIPCION"]; ?></div>
                        <div style="width: 200px; float: left; text-align: center;"><?php print $rTMP["TOTAL"]; ?></div>
                        <div style="width: 100px; float: left; text-align: right; border: none;">
                            <a style="border:none;" href="javascript:fntAcademicoCobrosContabilizacionPartida('<?php echo $url; ?>');" >
                                <img title="Contabilizar" src="../img/accepted.png" width="16" height="16" />
                            </a>
                            &nbsp;
                            <a style="border:none;" href="javascript:fntShowDetalleAnulacion('<?php echo $url; ?>');" >
                                <img title="Ver Cobros" src="../img/table-edit.png" width="16" height="16" />
                            </a>
                        </div>            
                    </div>
                    <?php
                }
                ?>
            </div>
            <div id="cobrosanulacion" style="display: block;" ></div>
            <script type="text/javascript">
                $("#cobrosanulacion").dialog({ 
                    modal:true,
                    autoOpen:false,
                    closable:true,
                    width:600,
                    height: 400,
                    title: "Anular Cobro",
                    position:['center','center'] 
                });     
            </script>
            <?php
        } else {
            ?>
            <div style="width: 800px; float: left;">
                <div class="ui-widget" style="width: 800px; height: auto;" align="center">
                    <div class="ui-state-highlight ui-corner-all" style="margin-top: 0px; padding: 0pt 0.7em; height: auto; width: 500px;"> 
                        <span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>
                        No se encontraron registros.
                    </div>
                </div>
            </div>
            <?php
        }
        $db->free_result($qTMP);
        ?>
    </div>
    <?php
}

function fntAcademicoCobrosContabilizacionPartida($db) {

    $intEmpresa = getParam("sltAcademicoCobrosContabilizacionEmpresas");
    $codgrado = getParam("idGrado");
    $codcargo = getParam("idCargo");
    $mes = getParam("idMes");

    $arrInfo = array();
    ?>
    <script type="text/javascript">
        var intEmpresa = '<?php print $intEmpresa; ?>';
    </script>
    <?php
    $strQuery = "select  b.ID, b.DESCRIPCION,
								b.CTA_COBRAR, 
								b.CTA_INGRESOS,	
								sum(c.VALOR) AS VALOR 						            
						from 	cllg_academico_cargos a, 
								cllg_academico_cargos_detail b, 
								cllg_academico_cobros c,
								cllg_academico_grados d
						  where 
						  c.ESTADO = 'INGRESADO' and
						  a.ID=b.FK_CARGOS and 
						  c.FK_CARGO_DETAIL_ID=b.ID and 
						  a.FK_GRADO=d.ID ";
    if ($codgrado == "999") {
        $strQuery = "select cm.ID,cm.DESCRIPCION, cm.CTA_INGRESOS,cm.CTA_CTASPORCOBRAR as CTA_COBRAR,sum(c.VALOR) AS VALOR from 	
            cllg_academico_cobros c, cllg_academico_cargo_cuenta cc, cllg_academico_cargo_manual cm
	where DATE_FORMAT(c.FECHA,'%m') = 5 and
        c.ESTADO = 'INGRESADO'  and
        c.FK_CARGO_MANUAL=cc.ID and cc.FK_CARGO_MANUAL=cm.ID GROUP BY cm.ID,cm.DESCRIPCION, cm.CTA_INGRESOS,cm.CTA_CTASPORCOBRAR";
    } else {
        $strQuery.=!isEmpty($codgrado) ? " and a.FK_GRADO = $codgrado " : "";
        $strQuery.=!isEmpty($mes) ? " and DATE_FORMAT(c.FECHA,'%m') = $mes " : "";
        $strQuery.=!isEmpty($mes) ? " and b.ID = $codcargo " : "";
        $strQuery.= " GROUP BY b.ID, b.DESCRIPCION,b.CTA_COBRAR, b.CTA_INGRESOS	";
    }
    $_SESSION["setcargos"] = serialize(array("grado" => $codgrado, "cargo" => $codcargo, "mes" => $mes));

    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        $arrInfo = $rTMP;
    }
    $db->free_result($qTMP);
    $arrAjuste = array();
    $sinMonto = mround($arrInfo["VALOR"], 2);
    $strQuery = "SELECT * 
                 FROM   cllg_contab_cuenta 
                 WHERE  fk_empresa = '{$intEmpresa}'
                 AND    codigo = '{$arrInfo["CTA_COBRAR"]}'";
    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        $arrAjuste["D" . $rTMP["codigo"]]["codigo"] = $rTMP["codigo"];
        $arrAjuste["D" . $rTMP["codigo"]]["nombre"] = $rTMP["nombre"];
        $arrAjuste["D" . $rTMP["codigo"]]["tipo"] = "d";
        $arrAjuste["D" . $rTMP["codigo"]]["monto"] = $sinMonto;
    }
    $db->free_result($qTMP);
    $strQuery = "SELECT * 
                 FROM   cllg_contab_cuenta 
                 WHERE  fk_empresa = '{$intEmpresa}'
                 AND    codigo = '{$arrInfo["CTA_INGRESOS"]}'";
    $qTMP = $db->query($strQuery);
    while ($rTMP = $db->fetch_array($qTMP)) {
        $arrAjuste["D" . $rTMP["codigo"]]["codigo"] = $rTMP["codigo"];
        $arrAjuste["D" . $rTMP["codigo"]]["nombre"] = $rTMP["nombre"];
        $arrAjuste["D" . $rTMP["codigo"]]["tipo"] = "h";
        $arrAjuste["D" . $rTMP["codigo"]]["monto"] = $sinMonto;
    }
    $db->free_result($qTMP);
    $ano = date("Y");
    $fechaSugerida = date("d-m-Y", strtotime("01-01-2012"));
    $descripcion = $arrInfo["DESCRIPCION"] . " - ($mes-$ano)";
    ?>
    <div style="width: 800px; float: left;">
        <div style="width: 800px; height: 40px; float: left; text-align: center;">
            <button type="button" id="btnAcademicoCobrosContabilizacionGrabar">Grabar</button>
        </div>
        <div style="width: 800px; float: left;">&nbsp;</div>
        <div style="width: 800px; float: left; text-align: center;"><b>Distribución contable</b></div>
        <div style="width: 800px; float: left;">&nbsp;</div>
        <div style="width: 800px; float: left">
            <input type="hidden" name="hdnAcademicoCobrosContabilizacionValor" value="<?php print $arrInfo["VALOR"]; ?>" />
            <input type="hidden" name="hdnAcademicoCobrosContabilizacionMonto" value="<?php print $arrInfo["VALOR"]; ?>" />
            <input type="hidden" name="hdnAcademicoCobrosContabilizacionConcepto1" value="<?php echo $descripcion; ?>" />
            <div style="width: 100px; float: left;">
                <b>Descripción</b><br />
            </div>    
            <div style="width: 700px; float: left;">
                <textarea name="hdnAcademicoCobrosContabilizacionConcepto" style="width: 100%"><?php print $descripcion; ?></textarea>
            </div>
            <div style="width: 800px; float: left">
                <div style="width: 100px; float: left">
                    <B><label>Fecha Partida </label></B>&nbsp;
                </div>    
                <div style="width: 600px; float: left">
                    <input type="text" name="hdnAcademicoCobrosContabilizacionFecha" id="hdnAcademicoCobrosContabilizacionFecha" value="<?php echo $fechaSugerida; ?>">
                </div>
                <div style="width: 800px; height: auto; float: left; text-align: center;">
                    <div id="frmPartidas-detalle" style="width: 800px; float: left;">
                        <div style="float: left; width: 400px; height: 30px; border-bottom: 1px solid black;"><b>Cuenta</b></div>
                        <div style="float: left; width: 200px; height: 30px; border-bottom: 1px solid black; text-align: center;"><b>Debe</b></div>
                        <div style="float: left; width: 200px; height: 30px; border-bottom: 1px solid black; text-align: center;"><b>Haber</b></div>
                        <div style="float: left; width: 400px; height: 10px;">&nbsp;</div>
                        <div style="float: left; width: 200px; height: 10px;">&nbsp;</div>
                        <div style="float: left; width: 200px; height: 10px;">&nbsp;</div>
                    </div>
                    <div id="frmPartidas-totales" style="width: 800px; float: left;">
                        <div style="float: left; width: 400px; height: 10px; border-collapse: separate; border-bottom: 1px solid black;">&nbsp;</div>
                        <div style="float: left; width: 200px; height: 10px; border-collapse: separate; border-bottom: 1px solid black;">&nbsp;</div>
                        <div style="float: left; width: 200px; height: 10px; border-collapse: separate; border-bottom: 1px solid black;">&nbsp;</div>
                        <div style="float: left; width: 400px; height: 30px; margin-top: 5px; text-align: right;"><b>Totales</b></div>
                        <div style="float: left; width: 200px; height: 30px; margin-top: 5px;"><input type="text" name="txtTotalDebe" id="txtTotalDebe" value="" style="text-align: right;" readonly="readonly"></div>
                        <div style="float: left; width: 200px; height: 30px; margin-top: 5px;"><input type="text" name="txtTotalHaber" id="txtTotalHaber" value="" style="text-align: right;" readonly="readonly"></div>
                    </div>
                </div>
                <div style="width: 800px; height: 40px; float: left; text-align: center;">
                    &nbsp;
                </div>
                <!--
                <div style="width: 800px; height: 40px; float: left; text-align: center;">
                    <button type="button" id="btnAcademicoCobrosContabilizacionGrabar">Grabar</button>
                </div> -->
                <script type="text/javascript">
                    $( function() {
                        $("#hdnAcademicoCobrosContabilizacionFecha").datepicker({changeYear:true,yearRange: 'c-50:c',dateFormat:'dd/mm/yy'});
                        $("#btnAcademicoCobrosContabilizacionGrabar").button({
                            icons: {
                                primary: "ui-icon-disk"
                            }
                        }).click( function () {
                            fntAcademicoCobrosContabilizacionGrabar();
                        }).button( "disable" );

    <?php
    reset($arrAjuste);
    $i = 1;
    while ($arrTMP = each($arrAjuste)) {
        ?>
                    intCorrelativo = <?php print $i; ?>;
                    drawNewLine(intCorrelativo, "<?php print $arrTMP["value"]["codigo"]; ?>", "<?php print $arrTMP["value"]["nombre"]; ?>", "<?php print $arrTMP["value"]["tipo"]; ?>", "<?php print $arrTMP["value"]["monto"]; ?>" );
        <?php
        $i++;
    }
    ?>
            intCorrelativo = <?php print $i; ?>;
            drawNewLine(intCorrelativo);
                                                                                                
        });
                </script>
            </div>
        </div>
    </div>
    <?php
}

function fntAcademicoCobrosContabilizacionGrabar($db) {

    $intEmpresa = getParam("sltAcademicoCobrosContabilizacionEmpresas");
    $valor = getParam("hdnAcademicoCobrosContabilizacionValor");
    $fecha = explode("-", getParam("hdnAcademicoCobrosContabilizacionFecha"));
    $fecha = $fecha[1] . "/" . $fecha[0] . "/" . $fecha[2];
    $fecha = date("Y-m-d", strtotime($fecha));

    $concepto = getParam("hdnAcademicoCobrosContabilizacionConcepto");

    $strQuery = "SELECT * 
                 FROM   cllg_contab_ciclo 
                 WHERE  activo = '1' 
                 AND    fecha_fin >= '{$fecha}'
                 AND    total_activo > 0 
                 AND    total_pasivo > 0
                 AND    fk_empresa = '{$intEmpresa}'";

    $qTMP = $db->query($strQuery);
    $intCicloCerrado = $db->num_rows;
    $db->free_result($qTMP);

    $strQuery = "SELECT * 
                 FROM   cllg_contab_ciclo 
                 WHERE  activo = '1' 
                 AND    '{$fecha}' >=fecha_inicio
                 AND    '{$fecha}'<=fecha_fin 
                 AND    fk_empresa = '{$intEmpresa}'";


    $qTMP = $db->queryToArray($strQuery);
    $intCicloCorrecto = count($qTMP);

    if ($intCicloCerrado > 0) {
        ?>
        <div class="ui-widget" style="border: 0px solid white; width: 800px; height: auto; vertical-align: bottom;" align="center">
            <div class="ui-state-error ui-corner-all" style="margin-top: 0px; padding: 0pt 0.7em; height: auto; width: 450px;"> 
                <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
                    No se puede ingresar partida en una fecha ya cerrada.</p>
            </div>
        </div>
        <br />
        <?php
    } else if ($intCicloCorrecto <= 0) {
        ?>
        <div class="ui-widget" style="border: 0px solid white; width: 800px; height: auto; vertical-align: bottom;" align="center">
            <div class="ui-state-error ui-corner-all" style="margin-top: 0px; padding: 0pt 0.7em; height: auto; width: 450px;"> 
                <span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
                La fecha de la factura esta fuera del rango del periodo actual abierto.
            </div>
        </div>
        <br />
        <?php
    } else {
        $strQuery = "SELECT * FROM cllg_contab_ciclo WHERE activo = '1' AND fk_empresa = '{$intEmpresa}'";
        $qTMP = $db->query($strQuery);
        $intNumRows = $db->num_rows;
        $rTMP = $db->fetch_array($qTMP);
        $intCiclo = $rTMP["codigo"];
        $db->free_result($qTMP);
        if ($intNumRows > 0) {

            $strQuery = "INSERT INTO cllg_contab_ajuste 
                         (id, fecha, monto, ciclo, descripcion)
                         VALUES
                         (NULL, '{$fecha}', {$valor}, '{$intCiclo}', '{$concepto}')";
            $db->query($strQuery);
            $intID = mysql_insert_id($db->link_id);

            if ($intID > 0) {

                while ($arrPost = each($_POST)) {

                    $arrExplode = explode("_", $arrPost["key"]);

                    if ($arrExplode[0] == "hdnCuenta" && $arrPost["value"] > 0) {

                        $debe = getParam("txtDebe_" . $arrExplode[1]);
                        $haber = getParam("txtHaber_" . $arrExplode[1]);
                        if ($debe > 0 && $haber == 0) {
                            $monto = $debe;
                            $debe = 1;
                            $haber = 0;
                        } else if ($debe == 0 && $haber > 0) {
                            $monto = $haber;
                            $debe = 0;
                            $haber = 1;
                        }
                        $strQuery = "INSERT INTO cllg_contab_cuenta_ajuste 
                                     (cuenta, debe, haber, monto, ajuste)
                                     VALUES
                                     ('{$arrPost["value"]}', '{$debe}', '{$haber}', '{$monto}', '{$intID}')";
                        $db->query($strQuery);
                    }
                }
                $setcargos = $_SESSION["setcargos"];
                $setcargos = unserialize($setcargos);
                $codcargo = $setcargos["cargo"];
                $mes = $setcargos["mes"];
                $strUpd = "UPDATE cllg_academico_cobros SET PARTIDA_CARGOS = '$intID' 
										WHERE DATE_FORMAT(FECHA,'%m')=$mes AND FK_CARGO_DETAIL_ID = $codcargo";
                $db->query($strUpd);
                unset($_SESSION["setcargos"]);
                ?>
                <div class="ui-widget" style="border: 0px solid white; width: 900px; height: auto; vertical-align: bottom;" align="center">
                    <div class="ui-state-highlight ui-corner-all" style="margin-top: 0px; padding: 0pt 0.7em; height: auto; width: 220px;"> 
                        <span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>
                        Partida ingresada No. <?php print $intID; ?>
                    </div>
                </div>
                <br />
                <script type="text/javascript" language="javascript">
                    fntAcademicoCobrosContabilizacionFacturas();
                    var objInterface = $("#divAcademicoCobrosContabilizacionPartida");
                    objInterface.html("");
                </script>
                <?php
            }
        }
    }
}

function mround($number, $precision = 0) {

    $precision = ($precision == 0 ? 1 : $precision);
    $pow = pow(10, $precision);

    $ceil = ceil($number * $pow) / $pow;
    $floor = floor($number * $pow) / $pow;

    $pow = pow(10, $precision + 1);

    $diffCeil = $pow * ($ceil - $number);
    $diffFloor = $pow * ($number - $floor) + ($number < 0 ? -1 : 1);

    if ($diffCeil >= $diffFloor)
        return $floor;
    else
        return $ceil;
}
?>
